﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using log4net;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

/// <summary>
/// Summary description for SerializationUtils
/// </summary>
public class SerializationUtils
{

    private static readonly ILog logger = LogManager.GetLogger(typeof(SerializationUtils));

    public SerializationUtils()
    {
        
    }

    public static void serialize(Object obj,String fileName)
    {
        Stream stream = File.Open(fileName, FileMode.Create);
        BinaryFormatter bformatter = new BinaryFormatter();

        logger.Debug("Writing Employee Information");
        bformatter.Serialize(stream, obj);
        stream.Close();

    }

    public static Object deserialize(String fileName)
    {
        Stream stream = File.Open(fileName, FileMode.Open);
        BinaryFormatter formatter = new BinaryFormatter();

        Console.WriteLine("Reading Employee Information");
        Object obj = formatter.Deserialize(stream);
        stream.Close();

        return obj;

    }
}
